﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace SimpleRentz
{
    class CardDeck
    {   
 
        public static List<Card> GetFullDeck(List<Card> pachet)
        {
            for (int i = 2; i < 15; i++)
            {
                pachet.Add(new Card(CardColor.Clubs, (CardValue)i));
                pachet.Add(new Card(CardColor.Diamonds, (CardValue)i));
                pachet.Add(new Card(CardColor.Hearts, (CardValue)i));
                pachet.Add(new Card(CardColor.Spades, (CardValue)i));
            }

            return pachet;
        }

        public static List<Card> Shuffle(List<Card> cardsToShuffle)
        {
            Random random = new Random();

            for (int i = 0; i < 2000; i++)
			{
                int index1 = random.Next(cardsToShuffle.Count);
                int index2 = random.Next(cardsToShuffle.Count);

                Card provizoriu = cardsToShuffle[index1];
                cardsToShuffle[index1] = cardsToShuffle[index2];
                cardsToShuffle[index2] = provizoriu;
            }

            return cardsToShuffle;
        }

        public static List<List<Card>> DealCards(List<Card> cardsToDeal, int numberOfPlayers)
        {
            List<List<Card>> pachetImpartit = new List<List<Card>>();

            for (int i = 0; i < numberOfPlayers; i++)
            {
                pachetImpartit.Add(new List<Card>());
            }
            foreach (List<Card> item in pachetImpartit)
            {
                for (int i = 0; i < cardsToDeal.Count / numberOfPlayers; i++)
                {
                    item[i] = cardsToDeal[i * 4 + pachetImpartit.IndexOf(item)];
                }
                item.Sort();
            }

            return pachetImpartit;
        }       
    }
}
